package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.pojo.dto.VmType;
import com.heima.mapper.VmTypeMapper;
import com.heima.pojo.dto.VmTypeQuery;
import com.heima.pojo.vo.PageVo;
import com.heima.service.IVmTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 售货机类型表 服务实现类
 * </p>
 *
 * @author 存折
 * @since 2024-10-20
 */
@Service
@Slf4j
public class VmTypeServiceImpl extends ServiceImpl<VmTypeMapper, VmType> implements IVmTypeService {


    @Autowired
    private VmTypeMapper vmTypeMapper;

    @Override
    public PageVo<VmType> query(VmTypeQuery vmTypeQuery) {
        String name = vmTypeQuery.getName();
        Page page=new Page<>(vmTypeQuery.getPageIndex(), vmTypeQuery.getPageSize());
        Page<VmType> p=lambdaQuery()
                .like(name!=null,VmType::getName,name)
                .page(page);
        long pages = p.getPages();
        long total = p.getTotal();
        List<VmType> records = p.getRecords();
        PageVo pageVo=new PageVo<>();
        pageVo.setPageIndex(vmTypeQuery.getPageIndex());
        pageVo.setPageSize(vmTypeQuery.getPageSize());
        pageVo.setTotalPage(pages);
        pageVo.setTotalCount(total);
        pageVo.setCurrentPageRecords(records);
        return pageVo;
    }
}
